/**
 * Created by mac on 2017/4/26.
 */
public class TestArgs {
    public static void main(String [] args) {

        int sum = 0, count = 0;
        int length = args.length;
        /*for(int i = 0; i<length; i++)
        {
            int temp = Integer.parseInt(args[i]);
            sum = sum + temp;
        }*/
		/* 参考Integer类中的方法把字符串转为整数
		补充代码求命令行参数的args中整数数据的和
        打印*/
        sum = clSum(args,count,sum);
        System.out.println(sum);
    }
    //递归函数
    public static int clSum(String [] arr, int count, int sum) {
        if(count == arr.length) {
            return sum;
        }
        else if(count<arr.length) {
            int temp = java.lang.Integer.parseInt(arr[count]);
            sum = sum + temp;
            count++;
            sum = clSum(arr,count,sum);
        }
        else
        {
            System.out.println("Error!");
        }
        return sum;
    }
}
